package Blocks;

import java.util.Iterator;
import java.util.LinkedList;

public class InitialBlock extends GeneralBlock
{
    private LinkedList<NextstateIntial> node;
    
    
    public InitialBlock()
    {
    	node = new LinkedList<NextstateIntial>();
    }
    
   
	public InitialBlock (LinkedList<NextstateIntial> startState) {
		node = startState;
	}

	public LinkedList<NextstateIntial> getNode() {
		return node;
	}

	public void setNode(LinkedList<NextstateIntial> node) {
		this.node = node;
	}

	public void add(int nextState, char curroutput, String output,String previousState) {
		String newOutput = output;
		newOutput= newOutput+curroutput;
		Iterator<NextstateIntial> it = node.iterator();
		boolean check = false;
		while (it.hasNext()) {
			NextstateIntial curr = it.next();
			if (newOutput.equals(curr.getOutput())) {
				curr.getNextState().set(nextState);
				curr.setInitialState(previousState);
				check = true;
				break;
			}
		}
		if (!check) {
			NextstateIntial newState = new NextstateIntial(nextState, output, curroutput,previousState);
			node.add(newState);
		}
	};
   
    

}
